<?
if (!defined('SMF'))
	die('Hacking attempt...');

global $smcFunc, $txt, $scripturl, $user_info;
global $dbtables, $color_line2, $color_line1;
	
// Verify user login, if CheckLogin() returns false return to the calling script/function
if (CheckLogin() == false)
	return;

if (isset($_GET['zone']))
	$zone = $_GET['zone'];
else
	return;

BigTitle($txt['bnt_zi_title']);

// Pull player info into $playerinfo.
$result = $smcFunc['db_query']('', '
	SELECT *
	FROM {raw:db_ships}
	WHERE user_id = {int:user_id}
	LIMIT 1',
	array(
		'db_ships' => $dbtables['ships'],
		'user_id' => $user_info['id'],
	)
);
$playerinfo = $smcFunc['db_fetch_assoc']($result);
$smcFunc['db_free_result']($result);

$result = $smcFunc['db_query']('', '
	SELECT *
	FROM {raw:db_zones}
	WHERE zone_id = {int:zone_id}',
	array(
		'db_zones' => $dbtables['zones'],
		'zone_id' => $zone
	)
);

if ($smcFunc['db_num_rows']($result) == 0)
	echo $txt['bnt_zi_nexist'];
else
{
	$row =  $smcFunc['db_fetch_assoc']($result);
	$smcFunc['db_free_result']($result);

	if ($row['zone_id'] < 5)
		$row['zone_name'] = $txt['bnt_zname'][$row['zone_id']];

	if ($row['zone_id'] == '2')
		$ownername = $txt['bnt_zi_feds'];
	elseif ($row['zone_id'] == '3')
		$ownername = $txt['bnt_zi_traders'];
	elseif ($row['zone_id'] == '1')
		$ownername = $txt['bnt_zi_nobody'];
	elseif ($row['zone_id'] == '4')
		$ownername = $txt['bnt_zi_war'];
	else
	{
		if ($row['corp_zone'] == 'N')
		{
			$result = $smcFunc['db_query']('', '
				SELECT ship_id, character_name
				FROM {raw:db_ships}
				WHERE ship_id = {int:ship_id}',
				array(
					'db_ships' => $dbtables['ships'],
					'ship_id' => $row['owner']
				)
			);
			$ownerinfo = $smcFunc['db_fetch_assoc']($result);
			$ownername = $ownerinfo['character_name'];
			$smcFunc['db_free_result']($result);
		}
		else
		{
			$result = $smcFunc['db_query']('', '
				SELECT team_name, creator, id
				FROM {raw:db_teams}
				WHERE id = {int:id}',
				array(
					'db_ships' => $dbtables['ships'],
					'id' => $row['owner']
				)
			);
			$ownerinfo = $smcFunc['db_fetch_assoc']($result);
			$ownername = $ownerinfo['character_name'];
			$smcFunc['db_free_result']($result);
		}
	}

	if ($row['allow_beacon'] == 'Y')
		$beacon = $txt['bnt_zi_allow'];
	elseif ($row['allow_beacon'] == 'N')
		$beacon = $txt['bnt_zi_notallow'];
	else
		$beacon = $txt['bnt_zi_limit'];

	if ($row['allow_attack'] == 'Y')
		$attack = $txt['bnt_zi_allow'];
	else
		$attack = $txt['bnt_zi_notallow'];

	if ($row['allow_defenses'] == 'Y')
		$defense = $txt['bnt_zi_allow'];
	elseif ($row['allow_defenses'] == 'N')
		$defense = $txt['bnt_zi_notallow'];
	else
		$defense = $txt['bnt_zi_limit'];

	if ($row['allow_warpedit'] == 'Y')
		$warpedit = $txt['bnt_zi_allow'];
	elseif ($row['allow_warpedit'] == 'N')
		$warpedit = $txt['bnt_zi_notallow'];
	else
		$warpedit = $txt['bnt_zi_limit'];

	if ($row['allow_planet'] == 'Y')
		$planet = $txt['bnt_zi_allow'];
	elseif ($row['allow_planet'] == 'N')
		$planet = $txt['bnt_zi_notallow'];
	else
		$planet = $txt['bnt_zi_limit'];

	if ($row['allow_trade'] == 'Y')
		$trade = $txt['bnt_zi_allow'];
	elseif ($row['allow_trade'] == 'N')
		$trade = $txt['bnt_zi_notallow'];
	else
		$trade = $txt['bnt_zi_limit'];

	if ($row['max_hull'] == 0)
		$hull = $txt['bnt_zi_ul'];
	else
		$hull = $row['max_hull'];

	if (($row['corp_zone'] == 'N' && $row['owner'] == $playerinfo['ship_id']) || ($row['corp_zone'] == 'Y' && $row['owner'] == $playerinfo['team'] && $playerinfo['ship_id'] == $ownerinfo['creator']))
		echo '<center>', $txt['bnt_zi_control'], ' <a href=', $scripturl, '?action=blacknova;sa=zoneedit;zone=', $zone, '> ', $txt['bnt_clickme'], '</a> ', $txt['bnt_zi_tochange'], '</center><p>';

	echo '
		<script type="text/javascript">
			$(document).ready(function(){
				// Table sorting function
				$(".bnt_table").tablesorter({
					headers: { 
						0: {sorter: false}
					},
					widgets: ["zebra"]
				});
			});
		</script>
		<table class="bnt_table">
			<thead>
				<tr>
					<th colspan="2">', $row['zone_name'], '</td>
				</tr>
			</thead>
			<tr>
				<td>', $txt['bnt_zi_owner'], '</td>
				<td>', $ownername, '</td>
			</tr>
			<tr>
				<td>', $txt['bnt_beacons'], '</td>
				<td>', $beacon, '</td>
			</tr>
			<tr>
				<td>', $txt['bnt_att_att'], '</td>
				<td>', $attack, '</td>
			</tr>
			<tr>
				<td>', $txt['bnt_md_title'], '</td>
				<td>', $defense, '</td>
			</tr>
			<tr>
				<td>', $txt['bnt_warpedit'], '</td>
				<td>', $warpedit, '</td>
			</tr>
			<tr>
				<td>', $txt['bnt_planets'], '</td>
				<td>', $planet, '</td>
			</tr>
			<tr>
				<td>', $txt['bnt_title_port'], '</td>
				<td>', $trade, '</td>
			</tr>
			<tr>
				<td>', $txt['bnt_zi_maxhull'], '</td>
				<td>', $hull, '</td>
			</tr>
		</table>';
}
?>
